
document.querySelector("html").style.fontSize = (window.innerWidth / 16) + "px";
window.onorientationchange = () => {
  window.location.reload();
};


function getParams() {
  let t = decodeURIComponent(window.location.href.split("?data=")[1]);
  ret = { difficulty: 0 };
  if (t) {
    try {
      ret = JSON.parse(t);
    } catch (error) {
    }
  }
  return ret;
}
$(function () {
  init();
  var Hcode
  var Icode
  var urlinfo = window.location.href

  // val=urlinfo.split("?")[1].split("=")[1];
  // console.log(decodeURI(val))

  function init() {
    $.ajax({
      url: 'https://jdb-demo.4ukids.cn/api/index',
      type: 'post',
      data: JSON.stringify({ user_level: getParams().difficulty }),
      headers: {
        'Content-Type': 'application/json;charset=utf8',
        'ACCESS-TOKEN': '0F242BEB-33A4-7CFB-BA85-950EC16F8485'
      },
      success: function (res) {
        Hcode = '';
        res = JSON.parse(res)
        console.log(res)
        var dataLength = res.data.list.length
        for (let i = 0; i < dataLength; i++) {
          Hcode += '<div class="mvideobox" data-img="' + res.data.list[i].video_img + '" data-value="' + res.data.list[i].video_id + '">' +
            '<img src="' + res.data.list[i].video_img + '" class="mvideoimg"/>' +
            '<div class="mvtitle">' +
            '<p>' + res.data.list[i].video_name_cn + '</p></div>' +
            '<div class="mvideoid">' +
            '<p>' + res.data.list[i].video_name_en + '</p></div></div>'

        }
        // console.log(Hcode)
        $("#mlist").append(Hcode)
        $("#difsel").click(function (e) {
          window.location = './difSel.html'
        })
        $(".mvideobox").click(function () {
          var value = $(this).data("value")
          var img = $(this).data("img");
          // if (img.substr(0, 5) != "https") {
          //   img = "https" + img.substr(4);
          // }
          var data = {
            value: value,
            img: img
          }
          data = JSON.stringify(data)
          console.log(data)
          window.location = './videoplay.html?data=' + data
        })
        $("#topimage").attr("src", res.data.recomment.video_img);
      }
    });
    let f = $(".footarea");
    if (window.innerHeight < f[0].offsetHeight + f[0].offsetTop) {
      f.addClass("hp");
      f.css("max-height", (window.innerHeight - f[0].offsetTop - 2) + "px");
    }
  }
})
